<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>转盘抽奖</title>
    <style>
body {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    margin: 0;
}

.roulette-container {
    position: relative;
}

.roulette {
    width: 300px;
    height: 300px;
    background-color: #f00;
    border-radius: 50%;
    position: relative;
    overflow: hidden;
}

.roulette-item {
    position: absolute;
    width: 50%;
    height: 100%;
    background-color: #fff;
    clip-path: polygon(0 0, 100% 50%, 0 100%);
    transform-origin: 100%;
    transform: rotate(var(--deg));
}

.spin-btn {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 20px;
    font-size: 16px;
    cursor: pointer;
}

    </style>
</head>
<body>
    <div class="roulette-container">
        <div class="roulette" id="roulette">
            <!-- 转盘扇形块 -->
            <div class="roulette-item" style="--deg: 0;"></div>
            <div class="roulette-item" style="--deg: 45deg;"></div>
            <div class="roulette-item" style="--deg: 90deg;"></div>
            <div class="roulette-item" style="--deg: 135deg;"></div>
            <div class="roulette-item" style="--deg: 180deg;"></div>
            <div class="roulette-item" style="--deg: 225deg;"></div>
            <div class="roulette-item" style="--deg: 270deg;"></div>
            <div class="roulette-item" style="--deg: 315deg;"></div>
        </div>
        <button class="spin-btn" onclick="startSpin()">开始抽奖</button>
    </div>

    <script>
      let spinning = false;

function startSpin() {
    if (!spinning) {
        spinning = true;
        const roulette = document.getElementById('roulette');
        const randomDegree = Math.floor(Math.random() * 360);
        const totalDegree = 360 * 5 + randomDegree; // 5圈再加上随机度数
        roulette.style.transition = 'transform 4s ease-out';
        roulette.style.transform = `rotate(${totalDegree}deg)`;
        setTimeout(() => {
            alert('恭喜你，抽中了奖品！');
            resetSpin();
        }, 4000); // 设置与transition时间相同的延迟
    }
}

function resetSpin() {
    const roulette = document.getElementById('roulette');
    roulette.style.transition = 'none';
    roulette.style.transform = 'rotate(0deg)';
    spinning = false;
}

    </script>
</body>
</html>
